/**
 *  Copyright [2011] Steffen Kämpke
 *  mailto: steffen.kaempke@pennychecker.de
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.pennychecker.example.mvp.presenter;

import com.google.inject.Inject;
import com.pennychecker.example.mvp.event.CloseViewEvent;
import com.pennychecker.example.mvp.event.CloseViewEventHandler;
import com.pennychecker.example.mvp.event.EditUserEvent;
import com.pennychecker.example.mvp.event.EditUserEventHandler;
import com.pennychecker.swing.mvp.SwingContainerDisplay;
import com.pennychecker.swing.mvp.SwingContainerPresenter;
import com.pennychecker.swing.mvp.event.EventBus;

/**
 *
 * @author Steffen Kämpke mailto:steffen.kaempke@pennychecker.de
 */
public class UserContainerPresenter extends SwingContainerPresenter<UserContainerPresenter.Display> {

    private final EditUserPresenter editUserPresenter;
    private final AllUserPresenter allUserPresenter;

    /**
     * 
     * @param display
     * @param eventBus
     * @param editUserPresenter
     * @param allUserPresenter 
     */
    @Inject
    public UserContainerPresenter(Display display, EventBus eventBus, EditUserPresenter editUserPresenter, AllUserPresenter allUserPresenter) {
        super(display, eventBus);

        assert null != editUserPresenter;
        assert null != editUserPresenter.getDisplay().asComponent().getName();
        this.editUserPresenter = editUserPresenter;

        assert null != allUserPresenter;
        assert null != allUserPresenter.getDisplay().asComponent().getName();
        this.allUserPresenter = allUserPresenter;

        display.addComponent(allUserPresenter.getDisplay().asComponent());
        display.showComponent(allUserPresenter.getDisplay().asComponent());
        
        bind();
    }

    @Override
    protected void onBind() {
        eventBus.addHandler(CloseViewEvent.TYPE, new CloseViewEventHandler() {

            public void onCloseViewEvent(CloseViewEvent event) {
                display.removeComponent(event.getComponent());
            }
        });

        registerHandler(eventBus.addHandler(EditUserEvent.TYPE, new EditUserEventHandler() {

            public void onEditUserEvent(EditUserEvent event) {
                display.addComponent(editUserPresenter.getDisplay().asComponent());
                display.showComponent(editUserPresenter.getDisplay().asComponent());
            }
        }));
    }

    public void refreshDisplay() {
    }

    public interface Display extends SwingContainerDisplay {
    }
}
